/**
 * 
 */
package activeQM;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.activemq.command.ActiveMQObjectMessage;

import Iview.IFormGestionRemota;
import stub.IGestionRemota;
import contenedorSpring.Contenedor;

/**
 * @author Elkin Torres
 * 
 */
public class clienteQMColaCompartirPantalla implements MessageListener {
	private Boolean estadoPantallaCompartida = true;

	@Override
	public void onMessage(Message arg0) {

		ActiveMQObjectMessage om = (ActiveMQObjectMessage) arg0;

		try {
			String ip = (String) om.getObject();
			IFormGestionRemota frame = (IFormGestionRemota) Contenedor.getSingleton().getApplicationContext().getBean("gestionRemota");
			IGestionRemota remoto = (IGestionRemota) Contenedor.getSingleton().getApplicationContext().getBean("servidorRMI");

			if (estadoPantallaCompartida && frame.solicitarAutorizacion(ip)) {
				estadoPantallaCompartida = false;
				remoto.iniciarCompartirPantalla(ip, true);
			} else {
				remoto.iniciarCompartirPantalla(ip, false);
			}
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
